package co.baiku.boot.core.orm.tools;


import co.baiku.boot.core.orm.bin.SqlParams;

import java.util.List;

/**
 * sql in 参数处理类
 */
public class SqlTools {

    public static void setInSql(List<Object> params, StringBuilder sqlBuffer, String column, Object[] values) {
        sqlBuffer.append(" ").append("and").append(" ").append(column).append(" ").append("in (");
        for (Object obj : values) {
            if (obj != null) {
                sqlBuffer.append(" ").append("?,");
                params.add(obj);
            }
        }
        sqlBuffer.delete(sqlBuffer.length() - 1, sqlBuffer.length());
        sqlBuffer.append(" ").append(")");
    }

    public static void setInSql(SqlParams params, StringBuilder sqlBuffer, String column, Object[] values) {
        sqlBuffer.append(" ").append("and").append(" ").append(column).append(" ").append("in (");
        for (Object obj : values) {
            if (obj != null) {
                sqlBuffer.append(" ").append("?,");
                params.addParams(obj);
            }
        }
        sqlBuffer.delete(sqlBuffer.length() - 1, sqlBuffer.length());
        sqlBuffer.append(" ").append(")");
    }
}
